<template>
	<view>
		<u-loading-page :loading="pageLoading"></u-loading-page>
		<view v-if="!pageLoading">
			<view class="categories">
				<view class="categories-item" :class="item.id == contentId ? 'action' : ''" v-for="item in info.serviceCategories"
					:style="{backgroundColor: item.bgColor,color:item.color}" @click="contentChange(item.id,item.color)">
					<view class="icon" :style="{backgroundColor:item.darkBgColor,color:item.color}"><text
							:class="item.icon"></text></view>
					<view class="mt-20">{{item.name}}</view>
				</view>
			</view>
			<view v-if="contentId" class="p-30" v-for="item in info.serviceContents[contentId]">
				<view style="font-size: 16px;font-weight:bold;color:#666" :style="{color:contentTitleColor}"><text class="mr-10"
						:class="item.icon"></text>{{item.title}}</view>
				<view class="">
					<view class="my-20" v-for="v in item.sections">
						<view style="font-size: 13px;color:#888;">{{v.title}}</view>
						<view class="mt-10" style="font-size: 14px;color:#444;">{{v.content}}</view>
					</view>
				</view>
			</view>
			<view class="p-30">
				<view class="p-30"
					style="display: flex;align-items: center;background-color: skyblue;color:white;border-radius: 15px;">
					<view style="flex-grow: 1;">
						<view style="font-size: 14px;">{{info.weatherInfo.location}}天气</view>
						<view class="mt-10" style="font-size: 12px;">今日天气预报</view>
						<view class="mt-20" style="font-size: 13px;">
							{{info.weatherInfo.condition}}，数据来源{{info.weatherInfo.source}}</view>
					</view>
					<view style="flex-shrink: 0;text-align: center;">
						<view><text style="font-size: 20px;" :class="info.weatherInfo.icon"></text></view>
						<view class="mt-10">{{info.weatherInfo.temperature.min}}℃~{{info.weatherInfo.temperature.max}}℃
						</view>
					</view>
				</view>
			</view>
			<view style="height:30rpx;"></view>
		</view>
	</view>
</template>

<script>
	import {
		getPageServices
	} from '@/config/api.js';
	export default {
		data() {
			return {
				pageLoading: true,
				contentId:'',
				contentTitleColor:'',
				info: {},
				options: {},
			}
		},
		onLoad(options) {
			this.options = options;
			this.getPageData(() => {
				this.pageLoading = false;
			});
		},
		onPullDownRefresh() {
			this.getPageData(function() {
				uni.stopPullDownRefresh();
			})
		},
		methods: {
			getPageData(cb) {
				getPageServices(this.options.level).then(res => {
					this.info = res.layout;
					this.contentId = res.layout.serviceCategories[0]['id'];
					this.contentTitleColor = res.layout.serviceCategories[0]['color'];
					typeof cb == 'function' && cb();
				});
			},
			contentChange(id,color){
				this.contentId = id;
				this.contentTitleColor = color;
			}
		}
	}
</script>

<style lang="scss">
	.categories {
		display: flex;
		flex-wrap: wrap;
		margin:  15rpx;

		.categories-item {
			width: calc(50% - 30rpx);
			margin: 15rpx;
			border-radius: 30rpx;
			padding: 30rpx;
			background-color: #ecfdf5;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			&.action{
				opacity: 0.8;
			}
			.icon {
				width: 40px;
				height: 40px;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 40px;
				background-color: lightcoral;
				color: white;
			}
		}
	}
</style>